Skip to content

Conversation

xrstf
Copy link
Contributor

@xrstf xrstf commented Oct 7, 2025

Summary

This PR implements an extension to the routing capabilities of the front-proxy. Previously it could only perform prefix matches (and those were mostly manually implemented), like sending everything beginning with /services/ to a virtual-workspace endpoint.

With this PR, the configured path in the front-proxy's mapping is treated a a path pattern like http.ServerMux expects it, i.e. placeholders like {cluster} can be used.

The use of these placeholders is limited since only core kcp code can access and make use of them. For now, there is a single special placeholder called {cluster} which can be used to provide a cluster context especially to virtual workspace endpoints (i.e. make the front-proxy understand that /services/myservice/clusters/abc123/apis/ refers to cluster abc123). This cluster context is then important when the per-workspace authentication feature is used.

I could see this being extended to help in per-shard routing for virtual workspaces, which is currently still an unsolved TODO: now more of the codebase uses a standard http.ServerMux, so it forms a good basis for extensions in the future.

However, the whole topic of routing in kcp is IMHO still quite confusing. There are special routes like /clusters/, there are multiple places throughout the codebase that use differnt methods of parsing URLs. I would at some point like to reorganize and clean it up a bit.


Code-wise, this PR replaces the ClusterResolver's custom string parsing to instead use a mux. This allows it to set the cluster in the request context, like we already do in the /clusters/-handler. Note that all configured mappings are added twice to the mux in order to be compatible with the old prefix-matching (configuring a path mapping /foo must match the literal /foo and /foo/bar, so two mux routes are necessary).

The proxy.HttpHandler was thinned out massively by simply relying on the already resolved data in the request context, rather than doing an index lookup and string parsing all over again. The trick to make this work was to not accidentally lose the query string parameters, which the ClusterResolver middleware up until now did when constructing the sharded target URL.

The mapping types were moved into a standalone package to solve an import loop.

What Type of PR Is This?

/kind feature

Release Notes

Path mappings in the front-proxy are treated as standard Go ServerMux patterns and can make use of the `{cluster}` placeholder to provide a cluster context to the WorkspaceAuthentication for virtual workspaces (e.g. `/services/myservice/clusters/{cluster}`).

@kcp-ci-bot kcp-ci-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the DCO. labels Oct 7, 2025
@kcp-ci-bot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kcp-ci-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from xrstf. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kcp-ci-bot kcp-ci-bot added do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 7, 2025
@xrstf
Copy link
Contributor Author

xrstf commented Oct 9, 2025

/test all

@xrstf xrstf force-pushed the more-path-mapping branch from 6bcb624 to c767a4d Compare October 10, 2025 15:29
@xrstf
Copy link
Contributor Author

xrstf commented Oct 10, 2025

/test all

@kcp-ci-bot kcp-ci-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 10, 2025
@xrstf
Copy link
Contributor Author

xrstf commented Oct 10, 2025

/test all

@kcp-ci-bot kcp-ci-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 10, 2025
@xrstf
Copy link
Contributor Author

xrstf commented Oct 10, 2025

/retest

@xrstf xrstf marked this pull request as ready for review October 10, 2025 18:33
@kcp-ci-bot kcp-ci-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 10, 2025
@embik
Copy link
Member

embik commented Oct 13, 2025

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants